package controle;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modelo.Professor;

/**
 * Servlet implementation class CadastrarAluno
 */
@WebServlet("/cadastrarProfessor")
public class CadastrarProfessor extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CadastrarProfessor() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Professor professor;
		try{
			Integer cod = Integer.valueOf(request.getParameter("cod"));
			String nome  = request.getParameter("nome");
			professor = new Professor(nome, cod);
			System.out.println("Nome: "+professor.getNome()+" cod"+professor.getCod());
		}catch(Exception e){
			String erro = "O códio :"+request.getParameter("cod")
					+"ou o nome: "+request.getParameter("nome")
					+"Não são entradas válidas";
			request.setAttribute("erro", erro);
			request.setAttribute("url", "cadastroProfessor.jsp");
			request.getRequestDispatcher("/erro").forward(request, response);
		}
		
		
		
			
		
	}

}
